/****************************************************************************************
**  File: Texture.hpp
**  Author: Asteroth
**  Date: 3-mag-2009
****************************************************************************************/

#ifndef __TEXTURE_HPP__
#define __TEXTURE_HPP__

class TextureHandle {
private:
	friend class Pixmap;
	GLuint handle;

public:
	TextureHandle(GLuint handle = 0) {this->handle = handle;}

	~TextureHandle() {
		if (handle!=0)
			glDeleteTextures(1, &handle);
	}

	inline GLuint getHandle() const {return handle;}
};

class Texture {
private:
	friend class Pixmap;
	estd::Pointer<TextureHandle> handle;

public:
	Texture(): handle(1) {}

	/// Returns the handle to the texture (read-only).
	inline GLuint getHandle() const {return handle()->getHandle();}

	/// Copy operator.
	inline Texture &operator = (const Texture &texture) {
		handle = texture.handle;
		return *this;
	}

	/// Binds this texture.
	inline void activate() {
		glBindTexture(GL_TEXTURE_2D, handle()->getHandle());
	}
};

#endif
